#include <stdio.h>
#include <e_file.h>
#include <unistd.h>
#include <fcntl.h>
int main (int argc, char **argv)
{
	//定义一把文件锁
	struct flock lock;
	int fd;
	//打开一个文件的权限和文件加锁的类型必须保持一致！
	fd = open (argv[1], O_RDONLY);
	if (-1 == fd) {
		perror ("open ()");
		return -1;
	}
	//初始化锁
	lock.l_type = F_RDLCK;
	lock.l_whence = SEEK_SET;
	lock.l_start = 0;
	lock.l_len = 7;

	//给文件加锁
	int f = fcntl (fd, F_SETLK, &lock);
	if (-1 == f) {
		perror ("fctnl()");
		return -1;
	}
	printf ("add read lock success...\n");
	getchar ();
	close (fd);
	return 0;
}
